﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using public_dbOpt;

namespace prjEMR22_154
{
    public partial class login_NewUser : Form
    {
        dbOPT dataOpt = new dbOPT();

        public login_NewUser()
        {
            InitializeComponent();
        }


        private void For_sure_Click(object sender, EventArgs e)
        {
            if (new_id.Text != "" && new_psw.Text != "")
            {
                new_check();
            }
            else
            {
                MessageBox.Show("输入有空项，请重新输入");
            }
        }
        public void new_check()
        {
            string sql = String.Format("select * from t_user where UName ='{0}'", new_id.Text);
            string sql2 = String.Format("select * from t_user where UName ='{0}'", new_id.Text);
            DataSet ds = new DataSet();//创建数据集
            ds = dataOpt.GetTable(sql);

            if (ds != null && ds.Tables[0].Rows.Count != 0)
            {
                // 处理用户存在的情况  
                MessageBox.Show("账号已存在。");
            }
            else
            {
                if(new_psw.Text != new_psw_sure.Text)
                {
                    MessageBox.Show("密码不一致。");
                }
                else if (admi.Checked == true)
                {
                    sql = String.Format("INSERT INTO t_user (UName, UPassword, UType) VALUES ('{0}', '{1}', '管理员')", new_id.Text,new_psw.Text);
                    MessageBox.Show("注册成功。");
                    this.Close();
                }
                else if (user.Checked == true)
                {
                    sql = String.Format("INSERT INTO t_user (UName, UPassword, UType) VALUES ('{0}', '{1}', '普通用户')", new_id.Text, new_psw.Text);
                    MessageBox.Show("注册成功。");
                    this.Close();
                }
                ds = dataOpt.GetTable(sql);
            }
            //MessageBox.Show(sql);

        }

        private void login_NewUser_Load(object sender, EventArgs e)
        {
            new_psw_sure.PasswordChar = '*';   //显示*
            new_psw.PasswordChar = '*';   //显示*
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                new_psw.PasswordChar = '\0';   //显示输入
            }
            else
            {
                new_psw.PasswordChar = '*';   //显示*
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                new_psw_sure.PasswordChar = '\0';   //显示输入
            }
            else
            {
                new_psw_sure.PasswordChar = '*';   //显示*
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void cencel_Click(object sender, EventArgs e)
        {
            Close();

        }

    }
}
